package com.example.common.config;

import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * TODO
 *
 * @author ding
 * @since 2024/7/22
 */
public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator {

    /**
     *
     * @param sec       配置对象
     * @param request   握手的请求
     * @param response  握手的响应对象
     */
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {

        //获取HttpSession对象
        HttpSession httpSession = (HttpSession) request.getHttpSession();
        //将httpSession对象保存
        sec.getUserProperties().put(HttpSession.class.getName(), httpSession);
    }
}
